import {Button, Form, Input} from 'antd'
import Layout from './Layout'
import axios from 'axios'
import {API} from '../../config'
import { useHistory } from 'react-router-dom'
function Signin () {
    const history = useHistory()
    const handleOnFinish = async value => {
        // 发送请求
        let response =  await axios.post(`${API}/signin`,value)
        // 存储数据
        localStorage.setItem("user",JSON.stringify(response.data))
        // 页面跳转
        const url = response.data.user.role === 1 ? "/admin/dashboard" : "/user/dashboard"
        history.push(url)

    }
    return(
        <Layout title="登陆" subTitle="">
            <Form onFinish={handleOnFinish}>
                <Form.Item name="email" label="邮箱">
                    <Input ></Input>
                </Form.Item>
                <Form.Item name="password" label="密码">
                    <Input.Password></Input.Password>
                </Form.Item>
                <Form.Item>
                    <Button type="primary" htmlType="submit">登陆</Button>
                </Form.Item>
            </Form>
        </Layout>
        
    )
}
export default Signin